
{block name="css"}

<link rel="stylesheet" type="text/css" href="__STATIC__/admin/hui/static/h-ui/css/H-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/hui/static/h-ui.admin/css/H-ui.admin.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/hui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/hui/static/h-ui.admin/skin/default/skin.css" id="skin"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/common.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/app.css"/>

{CSS href="__STATIC__/w/admin_base.css" /}
{CSS href="__STATIC__/w/laydate.css" /}
{CSS href="__STATIC__/w/layui.css" /}
{CSS href="__STATIC__/w/divtable.css" /}
{/block}

{block name="js"}
{js href='__STATIC__/w/jquery1110min.js' /}
{js href='__STATIC__/w/layui.js' /}
{/block}

{block name="main"}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 微信用户
    <a class="btn radius btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<form class="layui-form layui-form-cont" method="get" action="">

    <div class="layui-form-title">
        搜索微信用户
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">呢称</label>
        <div class="layui-input-block">
            <input type="text" name="nickname" class="layui-input" placeholder="请输入呢称" autocomplete="off" value="{$post.nickname}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">关注时间</label>
        <div class="layui-input-block" style="width: 200px;">
            <input type="text" name="times" class="layui-input" id="rhaphp-time1" placeholder="开始时间 到 结束时间" lay-key="17" value="{$post.times}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">互动时间</label>
        <div class="layui-input-block">
            <!--<input name="need" {eq name="$post" value="1" } checked {/eq} lay-skin="primary" value="1" title="有效"  type="checkbox">-->
            <input name="need" {eq name="$post" value="1" } checked {/eq}" value="1" title="有效"  type="checkbox">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input name="sex" {eq name="$post.sex" value="1" } checked {/eq} value="1" title="男" checked="" type="radio">
            <input name="sex" {eq name="$post.sex" value="2" } checked {/eq} value="2" title="女" type="radio">
            <input name="sex" {eq name="$post.sex" value="0" } checked {/eq} value="0" title="不限" type="radio">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="min-height: 1px;"></label>
        <div class="layui-input-block">
            <button type="submit" class="layui-btn">
                <i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
    </div>

</form>

<form class="layui-form layui-form-cont" action="" style="padding-top: 0px;">

    <div class="layui-form-title">
        微信用户列表
    </div>

    <table class="layui-table" lay-skin="line" style="margin-top: 0;">
        <colgroup>
            <col width="50">
            <col width="80">
            <col>
        </colgroup>

        <thead>
            <!--<tr>-->
            <!--<th>&nbsp;全部</th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--<th></th>-->
            <!--</tr>-->
            <tr>
                <th><input name="" lay-skin="primary" lay-filter="allChoose" type="checkbox"></th>
                <th></th>
                <th><a id="synselect" class="layui-btn radius layui-btn-sm" href="javascript:;">同步选中数丝信息</a><a id="getAllFriend" class="layui-btn radius layui-btn-sm" href="javascript:;">同步全部数丝</a></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
        </thead>

        <tbody>
        {volist name="list" id="v"}
        <tr>
            <td><input name="openid" value="{$v.openid}" lay-skin="primary" type="checkbox"></td>
            <td>
                <div  style="padding: 1px; border: #e6e6e6 solid 1px; width:35px; float: left; ">
                    <img class="form_logo" src="{$v.headimgurl}" width="35" height="35">
                </div>
            </td>
            <td>{$v.nickname}</td>
            <td>关注：{$v.subscribe_time|date="Y-m-d",###}</td>
            <td>
            <td></td>
            <td></td>
            <td><a class="rha-bt-a" href="{:url(\''.\\think\\Request::instance()->module().'/Wechatmessage/read',['uid'=>$v.id])}">发送消息</a></td>
        </tr>
        {/volist}
        </tbody>
    </table>
</form>
{$list->render()}
<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#rhaphp-time1'
            ,type: 'datetime'
            ,range: '到'
            ,format: 'yyyy-M-d'
        });
    })
    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form;

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });
    layui.use('layer', function(){
        var $ = layui.jquery, layer = layui.layer;
        var  lastOpenid='';
        var page='1';
        $(function () {

            $('#getAllFriend').click(function () {
                //send(lastOpenid,page);
                layer.open({
                    type: 2,
                    title: '同步全部粉丝',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['680px', '200px'],
                    content: '{:url("SynFriends")}',
                    cancel: function(index, layero){
                        window.location.reload();
                    }
                });
            });
            //这里有问题的js处理逻辑，后期记得更改
            function send (lastOpenid,page){
                $.post("{:url('SynFriends')}",{'lastOpenid':lastOpenid,'page':page},function (result) {
                    console.log(result);
                    if(result.status==1){
                        layer.msg('正在同步第'+result.page+'页', {
                            icon: 16
                            ,shade: 0.01,
                            time:0,
                        });
                        send(result.lastOpenid,result.page)
                    }
                    if(result.status==2){
                        //  layer.close(index);
                        layer.alert('同步完成', {
                            skin: 'layui-layer-lan'
                            ,closeBtn: 0
                        });
                        location.reload()

                    }
                    if(result.status==0){
                        layer.alert(result.msg, {
                            skin: 'layui-layer-lan'
                            ,closeBtn: 0
                        });
                    }

                })
            }
            $('#synselect').click(function () {
                var openids=[];
                $("input[name='openid']:checked").each(function (key,value) {
                    openids[key]=$(this).val();
                })
                $.post("{:url('SynSelect')}",{'openids':openids},function (result) {
                    layer.alert(result.msg, {
                        closeBtn: 0
                    });
                })
            })
        })
    });
</script>

{/block}
